www.gusucode.com > VC++ 客户管理系统(SQL Serve)-源码程序 > VC++ 客户管理系统(SQL Serve)-源码程序/code/Program/qylx.cpp

    // qylx.cpp : implementation file
//

#include "stdafx.h"
#include "khmanager.h"
#include "qylx.h"
#include "ado.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

int qylxclnum=0;
int qylxxiugai=0;
/////////////////////////////////////////////////////////////////////////////
// qylx dialog


qylx::qylx(CWnd* pParent /*=NULL*/)
	: CDialog(qylx::IDD, pParent)
{
	//{{AFX_DATA_INIT(qylx)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void qylx::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(qylx)
	DDX_Control(pDX, IDC_LIST1, m_list);
	DDX_Control(pDX, IDC_EDIT3, m_edit3);
	DDX_Control(pDX, IDC_EDIT2, m_edit2);
	DDX_Control(pDX, IDC_EDIT1, m_edit1);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(qylx, CDialog)
	//{{AFX_MSG_MAP(qylx)
	ON_COMMAND(ID_ADD, OnAdd)
	ON_COMMAND(ID_DELETE, OnDelete)
	ON_COMMAND(ID_EXIT, OnExit)
	ON_COMMAND(ID_UPDATE, OnUpdate)
	ON_COMMAND(ID_SAVE, OnSave)
	ON_COMMAND(ID_CANCEL, OnCancel)
	ON_NOTIFY(NM_DBLCLK, IDC_LIST1, OnDblclkList1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// qylx message handlers

BOOL qylx::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	imagelist.Create(32,32,ILC_COLOR32|ILC_MASK,0,0);
	imagelist.Add(::LoadIcon(::AfxGetResourceHandle(),MAKEINTRESOURCE(IDI_ICON1)));
	imagelist.Add(::LoadIcon(::AfxGetResourceHandle(),MAKEINTRESOURCE(IDI_ICON2)));
	imagelist.Add(::LoadIcon(::AfxGetResourceHandle(),MAKEINTRESOURCE(IDI_ICON3)));
	imagelist.Add(::LoadIcon(::AfxGetResourceHandle(),MAKEINTRESOURCE(IDI_ICON4)));
	imagelist.Add(::LoadIcon(::AfxGetResourceHandle(),MAKEINTRESOURCE(IDI_ICON5)));
	imagelist.Add(::LoadIcon(::AfxGetResourceHandle(),MAKEINTRESOURCE(IDI_ICON10)));
	
	CString s;
	TCHAR *pString;
	menu.LoadMenu(IDR_lxrxx);

	toolbar.EnableAutomation();
	toolbar.Create(WS_CHILD|WS_VISIBLE,CRect(0,0,0,0),this,ID_TOOLBAR);
	toolbar.SetImageList(&imagelist);

	int i;
	for(i=0;i<8;i++)
	{
	button[i].dwData=0;
	button[i].fsState=TBSTATE_ENABLED;
	button[i].fsStyle=TBSTYLE_BUTTON;
	}
	button[5].fsStyle=TBSTYLE_SEP;
	button[0].idCommand=ID_ADD;
	button[0].iBitmap=0;
	button[1].idCommand=ID_UPDATE;
	button[1].iBitmap=1;
	button[2].idCommand=ID_DELETE;
	button[2].iBitmap=2;
	button[3].idCommand=ID_SAVE;
	button[3].iBitmap=3;
	button[4].idCommand=ID_CANCEL;
	button[4].iBitmap=4;
	button[6].idCommand=ID_EXIT;
	button[6].iBitmap=5;
for(i=0;i<8;i++)
{
	s.LoadString(i+IDS_21);
	int nStringLength= s.GetLength() + 1;
	pString = s.GetBufferSetLength(nStringLength);
	
	button[i].iString =toolbar.AddStrings(pString);
		s.ReleaseBuffer();
}
	toolbar.AddButtons(7,button);
	toolbar.AutoSize();
	toolbar.SetStyle(TBSTYLE_FLAT|CCS_TOP);
	toolbar.EnableButton(ID_SAVE,false);
	toolbar.EnableButton(ID_CANCEL,false);

	m_list.ModifyStyle(0L,LVS_REPORT);
//	m_list.ModifyStyle(0L,LVS_SINGLESEL);
	m_list.ModifyStyle(0L,LVS_SHOWSELALWAYS);
	m_list.ModifyStyle(0L,LVS_NOSORTHEADER);
	m_list.SetExtendedStyle(LVS_EX_GRIDLINES|
		LVS_EX_FULLROWSELECT|
		LVS_EX_HEADERDRAGDROP|
		LVS_EX_ONECLICKACTIVATE);
	m_list.InsertColumn(0,"企业类型编号");
	m_list.InsertColumn(1,"企业类型名称");
	m_list.InsertColumn(2,"备注信息");
	
	m_list.SetColumnWidth(0,100);
	m_list.SetColumnWidth(1,100);
	m_list.SetColumnWidth(2,100);
	
	this->loadlist();
	this->enbalewin(false);
	this->datatotext();
	this->texttowin();
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void qylx::OnAdd() 
{
	
	this->enbalewin(true);
	this->enablebutton(false);
	this->clearall();
	this->autonum();
	
}

void qylx::OnCancel() 
{
this->enbalewin(false);
	this->enablebutton(true);
	qylxxiugai=0;
	this->datatotext();
	this->texttowin();
	
}

void qylx::OnDelete() 
{
ado rst;
CString ss,aa;
	this->m_edit1.GetWindowText(aa);
	if(aa.IsEmpty())
	{MessageBox("不能为空","提示");
	return;}
	if(MessageBox("删除后数据将丢失","提示",MB_YESNO)==IDYES)
	{

		ss.Format("delete from tb_Client_qylx where qylx_id = '%s'",aa);
	rst.ExecuteSQL(ss);
//rst.close();
m_list.DeleteAllItems();
this->loadlist();
this->datatotext();
this->texttowin();

	}
	
}

void qylx::OnExit() 
{
	this->EndDialog(true);
	
}

void qylx::OnUpdate() 
{
	CString ss,aa;
	this->m_edit1.GetWindowText(aa);
	if(aa.IsEmpty())
	{MessageBox("不能为空","提示");
	return;}
	this->enbalewin(true);
	this->enablebutton(false);
	qylxxiugai=1;
	
}
void qylx::OnSave() 
{
	ado rst;
	this->wintotext();
	CString ss,srept;
	srept.Format("select * from tb_Client_qylx where qylx_lxmc='%s'",edit2);
		rst.rstOpen(srept);
	if(rst.GetRecordCount()>0)
	{
		MessageBox("这个类型名称已经存在了","提示");
		return;
	}
	if(qylxxiugai==1)
	{ss.Format("UPDATE tb_Client_qylx set qylx_lxmc='%s',qylx_bz='%s' where qylx_id='%s'",edit2,edit3,edit1);}
	else
	{ss.Format("INSERT INTO tb_Client_qylx values('%s','%s','%s')",edit1,edit2,edit3);}
	rst.ExecuteSQL(ss);
	//rst.close();
	m_list.DeleteAllItems();
this->loadlist();
this->datatotext();
this->texttowin();
this->enbalewin(false);
	this->enablebutton(true);
	qylxxiugai=0;
	
}
void qylx::clearall()
{
	this->m_edit1.SetWindowText("");
	this->m_edit2.SetWindowText("");
	this->m_edit3.SetWindowText("");
}
void qylx::enablebutton(bool butn)
{
	toolbar.EnableButton(ID_ADD,butn);
	toolbar.EnableButton(ID_UPDATE,butn);
	toolbar.EnableButton(ID_DELETE,butn);
	toolbar.EnableButton(ID_SAVE,!butn);
	toolbar.EnableButton(ID_CANCEL,!butn);
}
void qylx::enbalewin(bool wi)
{
	this->m_edit1.EnableWindow(wi);
	this->m_edit2.EnableWindow(wi);
	this->m_edit3.EnableWindow(wi);
}
void qylx::texttowin()
{
	this->m_edit1.SetWindowText(edit1);
	this->m_edit2.SetWindowText(edit2);
	this->m_edit3.SetWindowText(edit3);
}
void qylx::wintotext()
{
	this->m_edit1.GetWindowText(edit1);
	this->m_edit2.GetWindowText(edit2);
	this->m_edit3.GetWindowText(edit3);
}
void qylx::datatotext()
{
	edit1=m_list.GetItemText(qylxclnum,0);
	edit2=m_list.GetItemText(qylxclnum,1);
	edit3=m_list.GetItemText(qylxclnum,2);
}
void qylx::loadlist()
{
	ado rst;
	rst.rstOpen("select * from tb_Client_qylx");
	int recordcount=rst.GetRecordCount();
int ii;
for(ii=1;ii<=recordcount;ii++)
{
m_list.InsertItem(ii-1,"");
m_list.SetItemText(ii-1,0,rst.GetFieldValue("qylx_id"));
m_list.SetItemText(ii-1,1,rst.GetFieldValue("qylx_lxmc"));
m_list.SetItemText(ii-1,2,rst.GetFieldValue("qylx_bz"));
rst.Move(ii);
}
rst.close();	
}
void qylx::autonum()
{
	ado rst3;
	rst3.rstOpen("select * from tb_Client_qylx");
		if(rst3.GetRecordCount()==0)
		{
this->m_edit1.SetWindowText("LX001");
this->m_edit1.EnableWindow(false);
return;
		}

	rst3.MoveLast();
	CString mm=rst3.GetFieldValue("qylx_id");
	int xuhao=atoi(mm.Right(3));
	xuhao+=1;
	mm.Format("LX%03d",xuhao);
	this->m_edit1.EnableWindow(false);
	
	this->m_edit1.SetWindowText(mm);
	rst3.close();
}


void qylx::OnDblclkList1(NMHDR* pNMHDR, LRESULT* pResult) 
{
qylxclnum=m_list.GetHotItem();
	if(qylxclnum<0)
	{return;}
	this->datatotext();
	this->texttowin();	
	this->enbalewin(false);
	this->enablebutton(true);
	
	*pResult = 0;
}

BOOL qylx::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class
	if(pMsg->message==WM_KEYDOWN && pMsg->wParam==13)
		pMsg->wParam=9;		
	return CDialog::PreTranslateMessage(pMsg);
}